﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>经费报销</title>
    <link href="/CSS/bootstrap3.3.5/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="/JqueryPlug/zTree_v3/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
    <link href="/CSS/V3/animate.css" rel="stylesheet">
    <link href="/CSS/font-awesome-4.3.0/css/font-awesome.css?v=4.3.0" rel="stylesheet">
    <link href="/CSS/V3/style.css?v=2.2.0" rel="stylesheet">
    <link href="/CSS/V3/BaseClassV3.css" rel="stylesheet" />
    <script src="/Scripts/jquery-1.11.2.min.js"></script>
    <script src="/CSS/bootstrap3.3.5/js/bootstrap.js"></script>
    <script src="/JqueryPlug/laypage/laypage.js"></script>
    <script src="/Scripts/avalon.js"></script>
    <script src="/Scripts/SZHLCommon.js?jsver=5"></script>
    <script src="/JqueryPlug/zTree_v3/js/jquery.ztree.core-3.5.js"></script>
    <script src="/JqueryPlug/zTree_v3/js/jquery.ztree.excheck-3.5.min.js"></script>
    <script>
        var zNodes = null;
        var zTreeObj = null;
        var model = avalon.define({
            $id: "APP_JFBX",
            JFBXItem: { "LeiBie": "", "BXJE": "", "BXContent": "", "BXDate": "" },
            JFBXItemList: [],//未报销的经费列表
            menutype: "-1",
            ColumnData: [],
            CommonData: [],
            searchContent: "",
            queryuser: ComFunJS.getnowuser(),
            fnqueryuser: function (item) {
                if (item) {
                    model.queryuser = item; //item.UserName;
                    model.CommonData.clear();
                    model.page = 0;
                    model.GetJFBXList();
                }

            },
            addxf: function () {
                if (model.JFBXItem.LeiBie == "") {
                    parent.ComFunJS.winwarning("请选择类型");
                    return;
                }
                if (model.JFBXItem.BXDate == "") {
                    parent.ComFunJS.winwarning("请选择日期");
                    return;
                }
                if (model.JFBXItem.BXJE == "") {
                    parent.ComFunJS.winwarning("请填写报销金额");
                    return;
                }
                if (!(/^[0-9]*$/.test(model.JFBXItem.BXJE))) {
                    parent.ComFunJS.winwarning("报销金额必须是数字");
                    return;
                }
                if (model.JFBXItem.BXJE == "0") {
                    parent.ComFunJS.winwarning("请输入大于0的报销金额");
                    return;
                }
                if (model.JFBXItem.BXContent == "") {
                    parent.ComFunJS.winwarning("请填写事由");
                    return;
                }

                var modelValue = JSON.stringify(model.JFBXItem.$model);
                $.post("/API/FTAPI.ashx", { Action: "ADDJFBXITEM", P1: modelValue }, function (result) {
                    result = $.parseJSON(result);
                    if ($.trim(result.ErrorMsg) != "") {
                        parent.ComFunJS.winwarning(result.ErrorMsg);
                    } else {
                        result.Result.issel = false;
                        model.JFBXItemList.push(result.Result);
                        parent.ComFunJS.winsuccess("保存成功");
                        model.JFBXItem = { "LeiBie": model.JFBXItem.LeiBie, "BXJE": "", "BXContent": "", "BXDate": "" };
                    }
                });
            },
            delxf: function (item) {
                model.JFBXItemList.remove(item);
                $.post("/API/FTAPI.ashx", { Action: "DELJFBXITEM", P1: item.ID },
             function (result) {
                 if ($.trim(result.ErrorMsg) != "") {
                     parent.ComFunJS.winwarning(result.ErrorMsg);
                 } else {
                     parent.ComFunJS.winsuccess("删除成功");
                 }
             });
            },
            GetJFBXItem: function () {
                //未报销的经费列表
                $.getJSON('/API/FTAPI.ashx?Action=GETJFBXITEMLIST', function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        resultData.Result.forEach(function (item) {
                            item.issel = false;
                        })
                        model.JFBXItemList = resultData.Result;

                    }
                })
            }, GetJFBXList: function () {
                //已添加的报销单
                $.getJSON('/API/FTAPI.ashx?Action=GETUSERJFBXLIST_PAGE', { P1: model.searchContent, P2: 1, b: model.menutype, QUSER: model.queryuser }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        model.CommonData = resultData.Result;
                        laypage({
                            cont: 'pageDiv', //容器。值支持id名、原生dom对象，jquery对象。
                            pages: Math.ceil(parseInt(resultData.Result1) * 1.0 / 8), //通过后台拿到的总页数
                            curr: 1, //初始化当前页
                            jump: function (e) { //触发分页后的回调
                                $.getJSON('/API/FTAPI.ashx?Action=GETUSERJFBXLIST_PAGE', { P1: model.searchContent, P2: 1, b: model.menutype, QUSER: model.queryuser }, function (resultData) {
                                    model.CommonData = resultData.Result;
                                })
                            }
                        });
                    }
                })
            },
            addJFBX: function () {

                var Ids = "";
                model.JFBXItemList.forEach(function (item) {
                    if (item.issel) {
                        Ids += item.ID + ",";
                    }
                })
                Ids = Ids.substring(0, Ids.length - 1);
                parent.ComFunJS.winviewform("/ViewV3/APPBaseView/APP_ADD_WF.html?FormCode=JFBX&type=经费报销&PDID=2&lctype=0&Ids=" + Ids, "经费报销", "1000", "");
            },
            CheckAll: function (dom) {
                var curClass = $(dom).attr("class");
                var addClass = ($(dom).hasClass("icon-weigouxuan") ? "iconfont icon-gouxuan" : "iconfont icon-weigouxuan");
                $(dom).removeClass(curClass).addClass(addClass);
                model.JFBXItemList.forEach(function (item) {
                    item.issel = $(dom).hasClass("icon-weigouxuan") ? false : true;
                })
            }, SelItem: function (item) {
                item.issel = item.issel == true ? false : true;
            },
            IsShowTR: false,
            getMenu: function () {
                var setting = {
                    data: {
                        simpleData: {
                            enable: true,
                            idKey: "id",
                            pIdKey: "pId",
                            rootPId: 0
                        }
                    },
                    view: {
                        showLine: false
                    },
                    callback: {
                        onClick: model.zTreeOnClick
                    }
                };
                $.ajax({
                    type: "GET",
                    url: "/API/SZHLAPI.ashx",
                    dataType: "html",
                    data: { "Action": "GETALLBMUSERLIST" },
                    success: function (msg) {
                        if (JSON.parse(msg).Result) {
                            model.IsShowTR = true;
                        }
                        zTreeObj = $.fn.zTree.init($("#tree"), setting, eval(JSON.parse(msg).Result));
                    }
                });
            },
            zTreeOnClick: function (event, treeId, treeNode) {
                model.queryuser = "";
                model.CommonData.clear();
                model.page = 0;
                if (treeNode.isUser) {
                    model.queryuser = treeNode.id;
                } else {
                    model.menutype = treeNode.id;
                    if (treeNode.children.length > 0 && treeNode.children[0].isUser) {

                        $(treeNode.children).each(function (i, user) {
                            model.queryuser += user.id + ",";
                        })
                        model.queryuser = model.queryuser.substring(0, model.queryuser.length - 1);
                    }
                }
                model.GetJFBXList();
            }
        })

        avalon.ready(function () {
            ComFunJS.initForm();
            ComFunJS.initsetajax();
            model.GetJFBXItem();
            //获取请假类型
            $.getJSON('/API/FTAPI.ashx?Action=GETCOLUMNLIST', { P1: 4 }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    model.ColumnData = resultData.Result;
                }
            })
            model.GetJFBXList();
            model.getMenu();
        })
        function ViewForm(ID, PIID) {
            parent.ComFunJS.winviewform("/ViewV3/APPBaseView/APP_ADD_WF.html?FormCode=JFBX&type=经费报销&PDID=2&lctype=0&ID=" + ID + "&PIID=" + PIID, "添加数据", "1000", "");
        }
    </script>

</head>
<body class="gray-bg" ms-controller="APP_JFBX">
    <div class="wrapper wrapper-content  animated fadeInRight">
        <div class="row">
            <div class="col-sm-3">
                <div class="ibox float-e-margins">
                    <div class="ibox-content" style="border: 0; border-right: 1px solid #e7eaec;">
                        <div class="file-manager">
                            <div class="hr-line-dashed"></div>
                            <button class="btn btn-primary btn-block" ms-click="addJFBX()">添加报销</button>
                            <div class="hr-line-dashed"></div>
                            <h4 class="tag-title"><a href="APP_JFBX.html">我的经费报销</a></h4>
                            <h4 class="tag-title" ms-if="model.IsShowTR">他人经费报销</h4>

                            <ul id="tree" ms-if="model.IsShowTR" class="ztree"></ul>


                            <div class="clearfix"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-9">
                <div class="ibox">
                    <div class="ibox-content text-center" style="border:0">

                        <h3 class="m-b-xxs" style="text-align:left">消费记录</h3>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <thead>
                                <tr>
                                    <th><i ms-click="CheckAll(this)" class="iconfont icon-weigouxuan" style="font-size:18px;vertical-align: sub;"></i></th>
                                    <th>消费类别</th>
                                    <th>金额</th>
                                    <th>时间</th>
                                    <th>事由</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr ms-repeat-item="model.JFBXItemList">
                                    <td>
                                        <i ms-click="SelItem(item,event)" class="iconfont" ms-class-1="icon-weigouxuan:!item.issel" ms-class-2="icon-gouxuan:item.issel" style="font-size:18px;vertical-align: sub;"></i>
                                    </td>
                                    <td>{{item.LeiBie}}</td>
                                    <td>{{item.BXJE}}</td>
                                    <td>{{item.BXDate|date("yyyy-MM-dd")}}</td>
                                    <td>{{item.BXContent}}</td>
                                    <td>
                                    <td>
                                        <a class="btn btn-danger btn-xs" ms-click="delxf(item)"><i class="fa fa-trash-o"></i> 删除 </a>
                                    </td>
                                </tr>

                            </tbody>
                            <tfoot>
                                <tr>
                                    <td colspan="2">
                                        <select class="form-control" ms-duplex="JFBXItem.LeiBie">
                                            <option value="">请选择</option>
                                            <option ms-repeat-item="ColumnData" ms-attr-value="item.TypeNO">{{item.TypeNO}}</option>
                                        </select>
                                    </td>

                                    <td><input type="text" class="form-control" ms-duplex="JFBXItem.BXJE" placeholder="消费金额"></td>
                                    <td><input type="text" class="form-control   szhl_form_date" placeholder="时间" ms-duplex="JFBXItem.BXDate"></td>
                                    <td><input type="text" class="form-control" placeholder="事由" ms-duplex="JFBXItem.BXContent"></td>
                                    <td colspan="2">
                                        <a class="btn btn-primary " ms-click="addxf()"><i class="fa fa-adjust"></i> 添加 </a>
                                    </td>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                    <div class="box" style="margin-bottom:15px;">

                        <div class="pull-right mail-search">
                            <div class="input-group">
                                <input type="text" class="form-control input-sm" ms-duplex="searchContent" name="search" placeholder="输入报销内容查询">
                                <div class="input-group-btn">
                                    <button type="submit" class="btn btn-sm btn-primary" ms-click="GetJFBXList()">
                                        搜索
                                    </button>
                                </div>
                            </div>
                        </div>
                        <h2>
                            经费报销
                        </h2>
                        <div class="mail-tools tooltip-demo m-t-md">
                            <div class="btn-group pull-right">
                                <div id="pageDiv" class="text-right"></div>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <thead>
                                <tr>
                                    <th>报销单号</th>
                                    <th>总金额</th>
                                    <th>申请人</th>
                                    <th>申请时间</th>
                                    <th>审批状态</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr ms-repeat-item="CommonData">
                                    <td>{{item.FormCode}}</td>
                                    <td>
                                        {{item.BXZJE}}
                                    </td>
                                    <td>{{item.ShenQingRen}}</td>
                                    <td>{{item.CRDate|date("yyyy-MM-dd")}}</td>
                                    <td ms-html="ComFunJS.getSPStatus(item.StateName, item.ID, item.intProcessStanceid)"></td>
                                </tr>

                            </tbody>
                        </table>
                    </div>
                </div>

            </div>
        </div>
    </div>
</body>
</html>
